<?php

class ManualController extends Controller {

	public function index() {
		$this->getSmarty ();
		$this->smarty->display ("manual/manual.tpl" );
	}
	
	public function manuallist(){
		require_once SERVICE.DS."CommonLogicService.class.php";
		$common = new CommonLogicService($this->getDB());
		$page = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rows = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		$offset = ($page - 1) * $rows;
		$result = array ();
		$row_count = $common->countNum("TCA_MANUAL_LIST");
		$result ["total"] = ceil($row_count/$rows);
		$result ["records"] = $row_count;
		$result ["page"] = $page;
		$user_infos = $common->dataPage("TCA_MANUAL_LIST", $offset, $rows );
		$items = array ();
		$result ["rows"] = $user_infos;
		echo json_encode ( $result );
	}
	
	public function manualAdd(){
		
		require_once SERVICE.DS."CommonLogicService.class.php";
		$common = new CommonLogicService($this->getDB());
		
		$manual_name = $_POST['manual_name'];
		$manual_type = $_POST['manual_type'];
		
		
		$name =date("Y-m-d_H-i-s");
        $direct =date("Y-m-d");
        $uploaddir = PROJECT.DS."upload".DS;//上传路径
        $pinfo=pathinfo($_FILES['upload']['name']);
        $ftype=$pinfo[extension];
        
		if(!file_exists($uploaddir.$direct)){
			mkdir($uploaddir.$direct);
  		}
		$filepath = $direct.DS.$name.".".$ftype;
         
		$destination = $uploaddir.$filepath; 
		
		$result = array ();
		
		if(move_uploaded_file($_FILES['upload']['tmp_name'],$destination)){

			$sql = "INSERT INTO TCA_MANUAL_LIST(MANUAL_NAME,MANUAL_TYPE,UPDATE_TIME) VALUES('$manual_name','$manual_type',SYSDATE())";
			//$sql = "INSERT INTO TCA_MANUAL_LIST(MANUAL_NAME,MANUAL_TYPE,UPDATE_TIME,FILE_NAME) VALUES('$manual_name','$manual_type',SYSDATE(),'$filepath')";
			$common->executeSql($sql);
			
			$result['success'] = true;
		}else{
			$result['success'] = false;
		}
		
		
		echo json_encode ( $result );
	}
}

?>